草庐IT

ruby Test::Unit 命令行选项?

全部标签

go - 如何在 Cobra golang 中使用子命令?

抱歉,我找不到使用示例的方法./clientecho--times10"coucou"./client--times10"coucou"echo无法使用它...抱歉我的错误。最好的问候,尼古拉斯funcmain(){varechoTimesintvarcmdEcho=&cobra.Command{Use:"echo[stringtoecho]",Short:"Echoanythingtothescreen",Long:`echoisforechoinganythingback.Echoworksalotlikeprint,exceptithasachildcommand.`,Run:f

go - 有什么办法可以在 exec.Command 中执行多个命令?

我正在尝试使用exec.Command()在Go中执行一组命令。我正在尝试使用DockerExec分离Gluster对等体。fmt.Println("Abouttoexecuteglusterpeerdetach")SystemdockerCommand:=exec.Command("sh","-c","dockerexec","9aa1124","glusterpeerdetach","192.168.1.1","force")varoutbytes.Buffervarstderrbytes.BufferSystemdockerCommand.Stdout=&outSystemdoc

unit-testing - 我如何在 Go 中编写使用 -short 标志的测试,它可以与 -benchmark 标志结合使用吗?

如何使用gotest-short中给出的-short标志?是否可以结合使用-short和-benchmark标志?我对Go语言还很陌生,但我正在努力使自己适应它的一些常见做法。其中一部分是尝试确保我的代码不仅以gotest系统工作的方式添加了单元测试,而且gotest-benchmark也以有用的方式运行方式。目前我有一个基准测试,其中包括一系列基于不同大小的输入数据的子测试。运行15个排列需要很长时间,因此最好提供缩短测试时间的选项。我计划编写的下一组测试可能包括一系列数据输入示例。我希望运行其中的一个可以作为短期测试的健全性检查,但可以选择在更长的(或正常的)测试运行中运行多个。当

unit-testing - 如何测试是否调用了 defer

我有以下代码func(s*MyRepo)InsertOrder(ctxcontext.Context,orderIDstring)error{query:=`INSERTINTOorders(orderID)VALUES(?)`stmt,err:=s.db.RawDatabase().PrepareContext(ctx,query)iferr!=nil{returnerr}deferstmt.Close()_,err=stmt.ExecContext(ctx,orderID)iferr!=nil{//logerr}returnerr}对应的测试用例是funcTestMyRepo_In

unit-testing - 如何在我的 go 测试中实现 faker?

我正在尝试学习Go并编写我的第一个测试。我想弄清楚如何实现一个伪造者来测试terraform上的CRUD。我已经弄清楚如何导入faker并创建要使用的变量。我尝试使用fmt.Println来查看它是否生成,但是如果它是一个测试,我在哪里可以看到Println。当我去测试时它不打印。functestCheckTritonUserDelete(s*terraform.State)error{fmt.Println("INsidetestCheckTritonUserDelete")fmt.Println(fake.UserName())returnnil//这是我要打印的函数

unit-testing - 在单元测试中使用随机数与硬编码值

这个问题在这里已经有了答案:WhatarethedownsidesusingrandomvaluesinUnitTesting?(11个答案)RandomdatainUnitTests?(20个答案)关闭3年前。当我写测试的时候,我喜欢用随机数来计算东西。例如funcinit(){rand.Seed(time.Now().UnixNano())}funcTestXYZ(t*testing.T){amount:=rand.Intn(100)cnt:=1+rand.Intn(10)fori:=0;i当然有缺点expected:=calcExpected(amount,cnt)因为需要根据随

go - 全局变量不会从 CLI 命令中保留下来

packagemainimport("fmt""net/http""os""strconv""github.com/go-chi/chi")vartests[]stringfuncmain(){iflen(os.Args[:])>1{tests=append(tests,"test")fmt.Println(strconv.Itoa(len(tests))+"tests")os.Exit(0)}r:=chi.NewRouter()r.Get("/",func(whttp.ResponseWriter,r*http.Request){tests=append(tests,"test")f

go - 如何在交互式 shell 中执行多个命令

我的应用程序使用控制台提供的所有类型的shell命令(curl、date、ping等等)。现在,我想使用os/exec来介绍交互式shell命令(如mongoshell)的案例。例如第一步,连接到mongodb:mongo--quiet--host=localhost博客然后执行任意数量的命令,获取每一步的结果db.getCollection('posts').find({status:'INACTIVE'})然后退出我尝试了以下方法,但它只允许我为每个mongo连接执行一个命令:funcmain(){cmd:=exec.Command("sh","-c","mongo--quiet-

bash - 在 Go 中执行带有参数的命令?

在我的shell中,我可以执行命令acme.sh--issue--dns-dexmaple.com--yes-I-know-dns-manual-mode-enough-go-ahead-please并获得输出。现在我想在go中执行此操作,我的代码如下:cmd:=exec.Command("bash","-c","acme.sh--issue--dns-dexmaple.com--yes-I-know-dns-manual-mode-enough-go-ahead-please");out,err:=cmd.CombinedOutput()iferr!=nil{log.Fatalf("

unit-testing - 如何为一小时后函数返回时间编写单元测试

我有以下函数,它在当前时间添加给定的小时数并在中返回新时间funcgetExpiryTime(hourint)*string{constlayout="2006-01-02T15:04:05Z"expiryTime:=time.Now().Local().Add(time.Hour*time.Duration(hour))returnaws.String(expiryTime.Format(layout))}为此功能编写单元测试的最佳方法是什么? 最佳答案 您可以尝试模拟时间提供程序并在您的模拟中设置time.Now()函数以返回您